/*
 * JDialogInserirTime.java
 *  Copyright (C) 2008  Tiago Silva Loureiro
 *  This File is part of Bier Manager.
 *  Bier Manager is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 * Created on 24 de Setembro de 2008, 21:11
 */

package biermanager.editorDeTimes.interfaceGrafica;

import biermanager.editorDeTimes.uteis.LimitaEdits;
import biermanager.nucleo.ImagemSerializada;
import biermanager.nucleo.Time;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author  tiagoloureiro
 */
public class JDialogInserirTime extends javax.swing.JDialog {

    /** Creates new form JDialogInserirTime
     * @param parent
     * @param modal 
     */
    public JDialogInserirTime(java.awt.Frame parent, boolean modal){
        super(parent, modal);
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
        setLocation( (int)( ( screenSize.getWidth() - this.getWidth() ) / 2 ), (int)( (screenSize.getHeight() - this.getHeight() - 40) / 2 ) );        
        nomeCompletoDoTime = null;
        nomeAbreviadoDoTime = null;
        cor1 = null;
        cor2 = null;
        cor = new Color[2];
        nivelInicialDoTime = 0;         //iniciando propriedades
        divisao = 0;
        moral = 0;
        img = null;
        time = new Time();
    }
        public JDialogInserirTime(java.awt.Frame parent, boolean modal, Time timeEdicao ) {
        super(parent, modal);
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
        setLocation( (int)( ( screenSize.getWidth() - this.getWidth() ) / 2 ), (int)( (screenSize.getHeight() - this.getHeight() - 40) / 2 ) );
        nomeCompletoDoTime = null;
        nomeAbreviadoDoTime = null;
        cor1 = null;
        cor2 = null;
        cor = new Color[2];
        nivelInicialDoTime = 0;
        jPanel8.setBackground( timeEdicao.getCores()[1] );
        jlCorDoTexto3.setForeground( timeEdicao.getCores()[0] );
        jtfNomeCompleto.setText( timeEdicao.getNomeCompleto() );
        jtfNomeAbreviado.setText(timeEdicao.getNomeAbreviado());
        jsNivelInicial.setValue( timeEdicao.getNivel() );
        cor1 = timeEdicao.getCores()[0];
        cor2 = timeEdicao.getCores()[1];                  //construtor 2 -> modo edicao
        jLabel2.setIcon( new ImageIcon( timeEdicao.getImagemSerializada().getImagem() ) );
        time = timeEdicao;
    }

    private boolean verificaPreenchimento(){
        if( !(jtfNomeCompleto.getText().isEmpty()) && jtfNomeCompleto.getText().length() > 9 && jtfNomeCompleto.getText().length() < 31 ){
            if( !(jtfNomeAbreviado.getText().isEmpty()) && jtfNomeAbreviado.getText().length() > 3 && jtfNomeAbreviado.getText().length() < 21 ){
                    if( cor1 != null && cor2 != null ){
                        if( (Integer)jsNivelInicial.getValue() != 0 ){
            return(true);}
        else
           JOptionPane.showMessageDialog(null, "Erro ao selecionar o nivel Inicial do seu time!");
        }
        else
           JOptionPane.showMessageDialog(null, "As cores do seu time devem ser selecionadas!");
        }
        else
            JOptionPane.showMessageDialog(null, "O campo Nome Abreviado deve estar preenchido e conter entre 4 e 20 caracteres!");
        }
        else
            JOptionPane.showMessageDialog(null, "O campo Nome Completo deve estar preenchido e conter entre 10 e 30 caracteres!");
        return(false);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jtfNomeAbreviado = new javax.swing.JTextField();
        jlNomeAbreviado = new javax.swing.JLabel();
        jlNivelInicial = new javax.swing.JLabel();
        jsNivelInicial = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jtfNomeCompleto = new javax.swing.JTextField();
        jlNomeCompleto = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jbInserir = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jlbSelecionarCorDeFundo3 = new javax.swing.JButton();
        jbSelecionarCorDoTexto3 = new javax.swing.JButton();
        jlCor1Ok3 = new javax.swing.JLabel();
        jlCor2Ok3 = new javax.swing.JLabel();
        jlCorDoTexto3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Inserir Time");
        setModal(true);
        setResizable(false);

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setMaximumSize(new java.awt.Dimension(500, 32767));
        jPanel4.setPreferredSize(new java.awt.Dimension(250, 132));

        jtfNomeAbreviado.setDocument(new LimitaEdits( 20 ));
        jtfNomeAbreviado.setToolTipText("Insira o nome abreviado da equipe");

        jlNomeAbreviado.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlNomeAbreviado.setText("Nome Abreviado");

        jlNivelInicial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlNivelInicial.setText("Nivel Inicial do Time");

        jsNivelInicial.setModel(new javax.swing.SpinnerNumberModel(20, 1, 99, 1));
        jsNivelInicial.setToolTipText("Escolha valor para Força Inicial da equipe: (Valor entre 1 e 99)");
        jsNivelInicial.setEditor(new javax.swing.JSpinner.NumberEditor(jsNivelInicial, "00"));
        jsNivelInicial.setValue(12);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Divisão");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Laudelino", "Negosvaldo" }));

        jtfNomeCompleto.setDocument( new LimitaEdits( 30 ));
        jtfNomeCompleto.setToolTipText("Insira o nome completo da equipe");

        jlNomeCompleto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlNomeCompleto.setText("Nome Completo do Time");

        jLabel2.setBackground(new java.awt.Color(255, 255, 204));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setMaximumSize(new java.awt.Dimension(149, 23));
        jLabel2.setMinimumSize(new java.awt.Dimension(149, 23));

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setText("Selecionar Bandeira");
        jButton1.setMaximumSize(new java.awt.Dimension(149, 23));
        jButton1.setMinimumSize(new java.awt.Dimension(149, 23));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlNomeCompleto)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jsNivelInicial, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                    .addComponent(jlNivelInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfNomeAbreviado, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                    .addComponent(jlNomeAbreviado, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))
                .addGap(20, 20, 20))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlNomeCompleto)
                            .addComponent(jlNomeAbreviado))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfNomeAbreviado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jlNivelInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jsNivelInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(15, 15, 15))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jbInserir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbInserir.setText("Inserir Time");
        jbInserir.setToolTipText("Clique para inserir o time");
        jbInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbInserirActionPerformed(evt);
            }
        });

        jbCancelar.setText("Cancelar");
        jbCancelar.setToolTipText("Clique para cancelar a inserção");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGap(115, 115, 115)
                .addComponent(jbInserir, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 144, Short.MAX_VALUE)
                .addComponent(jbCancelar)
                .addGap(94, 94, 94))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbInserir, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel8.setPreferredSize(new java.awt.Dimension(300, 177));

        jlbSelecionarCorDeFundo3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbSelecionarCorDeFundo3.setText("Selecionar Cor de Fundo");
        jlbSelecionarCorDeFundo3.setToolTipText("Clique para selecionar a cor de fundo padrão para  a equipe");
        jlbSelecionarCorDeFundo3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jlbSelecionarCorDeFundo3ActionPerformed(evt);
            }
        });

        jbSelecionarCorDoTexto3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbSelecionarCorDoTexto3.setText("Selecionar Cor do Texto");
        jbSelecionarCorDoTexto3.setToolTipText("Clique para selecionar a cor de texto padrão da equipe");
        jbSelecionarCorDoTexto3.setMaximumSize(new java.awt.Dimension(149, 23));
        jbSelecionarCorDoTexto3.setMinimumSize(new java.awt.Dimension(149, 23));
        jbSelecionarCorDoTexto3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSelecionarCorDoTexto3ActionPerformed(evt);
            }
        });

        jlCor1Ok3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlCor1Ok3.setMaximumSize(new java.awt.Dimension(149, 23));
        jlCor1Ok3.setMinimumSize(new java.awt.Dimension(149, 23));

        jlCor2Ok3.setMaximumSize(new java.awt.Dimension(149, 23));
        jlCor2Ok3.setMinimumSize(new java.awt.Dimension(149, 23));

        jlCorDoTexto3.setFont(new java.awt.Font("Tahoma", 1, 30)); // NOI18N
        jlCorDoTexto3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlCorDoTexto3.setText("Bier Manager");
        jlCorDoTexto3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jlCorDoTexto3.setMaximumSize(new java.awt.Dimension(149, 23));
        jlCorDoTexto3.setMinimumSize(new java.awt.Dimension(149, 23));
        jlCorDoTexto3.setOpaque(true);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbSelecionarCorDoTexto3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlbSelecionarCorDeFundo3, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jlCor2Ok3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlCor1Ok3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlCorDoTexto3, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlCorDoTexto3, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false)
                            .addComponent(jlbSelecionarCorDeFundo3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlCor1Ok3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false)
                            .addComponent(jbSelecionarCorDoTexto3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlCor2Ok3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbInserirActionPerformed
    if( verificaPreenchimento() ){
        cor[0] = cor1;
        cor[1] = cor2;
        time.setNomeCompleto(jtfNomeCompleto.getText());
        time.setNomeAbreviado(jtfNomeAbreviado.getText());
        time.setCores(cor);
        time.setNivel((Integer) jsNivelInicial.getValue());
        time.setDivisao(jComboBox1.getSelectedIndex());
        time.setMoral(0);
        time.setImagem(img);
        this.dispose();
    }
}//GEN-LAST:event_jbInserirActionPerformed

private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
    if (JOptionPane.showConfirmDialog(null, "Deseja finalizar sem inserir o time?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
            this.dispose();
}//GEN-LAST:event_jbCancelarActionPerformed

private void jlbSelecionarCorDeFundo3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jlbSelecionarCorDeFundo3ActionPerformed
    cor2 = JColorChooser.showDialog(this,"Insira a sua cor" , Color.white );
    jlCorDoTexto3.setBackground(cor2);
}//GEN-LAST:event_jlbSelecionarCorDeFundo3ActionPerformed

private void jbSelecionarCorDoTexto3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSelecionarCorDoTexto3ActionPerformed
    cor1 = JColorChooser.showDialog(this,"Insira a sua cor" , Color.white );
    jlCorDoTexto3.setForeground( cor1 );
}//GEN-LAST:event_jbSelecionarCorDoTexto3ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        FileDialog dialogoDeArquivos = new FileDialog( this, "Escolha a bandeira do seu time", FileDialog.LOAD );
        dialogoDeArquivos.setVisible(true);
        if(dialogoDeArquivos.getFile() != null){
            File arquivo =  new File(dialogoDeArquivos.getDirectory().concat(dialogoDeArquivos.getFile()));
            Image imagem = null;
            try {
                imagem = ImageIO.read(arquivo);
            } catch (IOException ex) {
                Logger.getLogger(JDialogInserirTime.class.getName()).log(Level.SEVERE, null, ex);
            }
                img = new ImagemSerializada(imagem, 100, 100);
            jLabel2.setIcon(new ImageIcon(img.getImagem()));
        }
        else
            time.setImagem(null);
}//GEN-LAST:event_jButton1ActionPerformed

public Time getTime(){
    return(this.time);  
}





private Time   time;
private String nomeCompletoDoTime;
private String nomeAbreviadoDoTime;
private Color[] cor;
private Color cor1;
private Color cor2;
private int nivelInicialDoTime;
private int divisao;
private int moral;
private ImagemSerializada img;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbInserir;
    private javax.swing.JButton jbSelecionarCorDoTexto3;
    private javax.swing.JLabel jlCor1Ok3;
    private javax.swing.JLabel jlCor2Ok3;
    private javax.swing.JLabel jlCorDoTexto3;
    private javax.swing.JLabel jlNivelInicial;
    private javax.swing.JLabel jlNomeAbreviado;
    private javax.swing.JLabel jlNomeCompleto;
    private javax.swing.JButton jlbSelecionarCorDeFundo3;
    private javax.swing.JSpinner jsNivelInicial;
    private javax.swing.JTextField jtfNomeAbreviado;
    private javax.swing.JTextField jtfNomeCompleto;
    // End of variables declaration//GEN-END:variables

}
